import { OssController } from './oss-controller'; 
import { getUploadParams } from './get-upload-params';
import { getApplicationContainer } from './../../get-application-container';
import { OssConfigModel, OssCredentialsModel, OssPolicyModel } from '../../core/api/models/oss-config-model';

let SEQUENCE = 100;

declare var wx: any;

export function wxUploadFile(path = '"http://xq-treasure-community.oss-cn-shanghai.aliyuncs.com/hot/default/hot_news_default.jpg',policyConfig: any,objectKey: any): Promise<string> {
    return new Promise(async function (resolve, reject) {
        //const ossBaseConfig = await OssController.getOssBaseConfig();
        //const credentials = (await OssController.getOssCredentials());
        //const params = await getUploadParams(credentials);
       
        //const securityToken = credentials.securityToken;
        

        // https://sce-dev-test-private.oss-cn-shanghai.aliyuncs.com/design-inspect/t-1613710424502-s-102.jpg
        //const host = `https://${ossBaseConfig.endpoint}`;
        wx.uploadFile({
            url: policyConfig.host, // 开发者服务器的URL。
            filePath: path,
            name: 'file', // 必须填file。
            formData: {
                key: objectKey,
                policy: policyConfig.policy,
                OSSAccessKeyId: policyConfig.accessid,
                signature: policyConfig.signature,
                'x-oss-security-token': '' // 使用STS签名时必传。
            },
            success: (res: any) => {
                //console.log(res);
                resolve(`${policyConfig.host}/${objectKey}`);
            },
            fail: (err: any) => {
                console.log(err);
                reject(err);
            }
        });
    });

}